f1e7f7c01f502cd9ed6e389c75fb23857e655162,src/org/wikipedia/Wiki.java,Wiki,fetch,#String#String#,7233
Before Change
protected String fetch(String url, String caller) throws IOException
{
// connect
logurl(url, caller);
URLConnection connection = makeConnection(url);
connection.setConnectTimeout(CONNECTION_CONNECT_TIMEOUT_MSEC);
connection.setReadTimeout(CONNECTION_READ_TIMEOUT_MSEC);
After Change
{
String temp = "";
int tries = maxtries;
do
{
logurl(url, caller);
tries--;
try
{
// connect
URLConnection connection = makeConnection(url);
connection.setConnectTimeout(CONNECTION_CONNECT_TIMEOUT_MSEC);
connection.setReadTimeout(CONNECTION_READ_TIMEOUT_MSEC);
setCookies(connection);
connection.connect();
grabCookies(connection);
// check lag and retry
if (checkLag(connection))
return fetch(url, caller);
// get the text
String line;
StringBuilder text = new StringBuilder(100000);
try (BufferedReader in = new BufferedReader(new InputStreamReader(
zipped ? new GZIPInputStream(connection.getInputStream()) : connection.getInputStream(), "UTF-8")))
{
while ((line = in.readLine()) != null)
{
text.append(line);
text.append("\n");
}
}
temp = text.toString();
}
catch (IOException ex)
{
if (tries == 0)
throw ex;
try
{
Thread.sleep(10000);
}
catch (InterruptedException ignored)
{
}
}
}
while (temp.isEmpty());
if (temp.contains("<error code="))
{
// assertions